package com.jytc.framework.commons;

import java.util.List;

import com.jytc.framework.dto.FwPermissionDTO;

/**
 * @title: PermissionTree.java
 * @description: 权限树
 * 
 * @author: dongyuese
 *
 */
public class PermissionTree
{

	/**
	 * 所有权限数据
	 */
	private List<FwPermissionDTO> permissions = null;

	/**
	 * 复选框默认为选中状态列表
	 */
	private List<String> defaultCheckedNodes = null;

	private final String permissionTreeXml = null;

	public String getPermissionTreeXml()
	{
		String treeXml = "";
		try
		{
			Tree menuTree = new Tree();
			for (FwPermissionDTO fwPermissionDTO : permissions)
			{
				TreeNode node = new TreeNode(String.valueOf(fwPermissionDTO.getPermissionId()));
				node.setText(fwPermissionDTO.getPermissionName());
				node.setParentId(String.valueOf(fwPermissionDTO.getParentPermissionId()));
				menuTree.addNode(node);
			}
			//设置默认选中状态
			menuTree.setNodeChecked(defaultCheckedNodes);
			treeXml = menuTree.getXml();
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return treeXml;
	}

	public void setPermissions(List<FwPermissionDTO> permissions)
	{
		this.permissions = permissions;
	}

	public void setDefaultCheckedNodes(List<String> defaultCheckedNodes)
	{
		this.defaultCheckedNodes = defaultCheckedNodes;
	}

}
